package com.dw.dwdzcommerce.view.mainContent.ad;

import java.util.ArrayList;
import java.util.List;

import com.dw.dwdzcommerce.R;
import com.dw.dwdzcommerce.base.fragment.BaseFragment;
import com.dw.dwdzcommerce.entity.AdPage;
import com.dw.dwdzcommerce.tools.commons.bitmap.BitmapUtil;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;

public class ADItemFragment extends BaseFragment {
	private ImageView mRootView;
	private AdPage dataPage;

	@Override
	public int getViewLayout() {
		return R.layout.item_fragment_adpager;
	}

	public static List<Fragment> mkFragments(List<AdPage> adPages) {
		List<Fragment> fragments = new ArrayList<Fragment>(adPages.size());
		for (int i = 0; i < adPages.size(); i++) {
			ADItemFragment fragment = new ADItemFragment();
			fragment.setImage(adPages.get(i));
			fragments.add(fragment);
			
		}
		return fragments;
	}

	public void setImage(AdPage page) {
		this.dataPage = page;

	}

//	private void ruleImageView() {
//		mRootView.post(new Runnable() {
//
//			@Override
//			public void run() {
//				LayoutParams layoutParams = mRootView.getLayoutParams();
//				int width = layoutParams.width;
//				int height = (int) (layoutParams.width / 1.6);
//				layoutParams.width = width;
//				layoutParams.height = height;
//				mRootView.setLayoutParams(layoutParams);
//			}
//		});
//
//	}

	@Override
	protected void initView(View view) {
		mRootView = (ImageView) view;
//		 ruleImageView();
		String adPicUrl = dataPage.getAdPicUrl();
		 BitmapUtil.loadImage(mRootView, adPicUrl, getActivity());
//		mRootView.setImageResource(R.drawable.ic_launcher);
		
		
	}

	@Override
	protected void bindView(View view) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onViewGreate(View view, Bundle savedInstanceState) {
		// TODO Auto-generated method stub

	}

}
